/**
 * 厦门大学计算机专业 | 前华为工程师
 * 专注《零基础学编程系列》https://lblbc.cn/blog
 * 包含：Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙
 * 公众号：蓝不蓝编程
 **/
const app = getApp()
var interval = 0;
var isStarted = false;
Page({
  data: {
    startPauseButtonText: '开始',
    ball1: '15',
    ball2: '15',
    ball3: '15',
    ball4: '15',
    ball5: '15',
    ball6: '15',
    ball7: '15'
  },

  startOrPauseTimer() {
    if (isStarted) {
      clearInterval(interval);

      this.setData({
        startPauseButtonText: '开始'
      });
    } else {
      this.setData({
        startPauseButtonText: '暂停'
      });

      interval = setInterval(() => {
        this.setData({
          ball1: this.getRandom(33),
          ball2: this.getRandom(33),
          ball3: this.getRandom(33),
          ball4: this.getRandom(33),
          ball5: this.getRandom(33),
          ball6: this.getRandom(33),
          ball7: this.getRandom(16)
        });
      }, 100);
    }

    isStarted = !isStarted;
  },

  getRandom(maxNum) {
    return Math.floor(Math.random() * maxNum)+1
  },

});